define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'usertx/record/index' + location.search,
                    add_url: 'usertx/record/add',
                    edit_url: 'usertx/record/edit',
                    del_url: 'usertx/record/del',
                    multi_url: 'usertx/record/multi',
                    import_url: 'usertx/record/import',
                    table: 'user_tx_record',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'uid', title: __('Uid')},
                        {field: 'tx_number', title: __('Tx_number'), operate: 'LIKE'},
                        {field: 'user.nickname', title: '用户昵称', operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'actual_price', title: __('Actual_price'), operate: 'LIKE'},
                        {field: 'payee_name', title: __('Payee_name'), operate: 'LIKE'},
                        {field: 'bank_name', title: __('Bank_name'), operate: 'LIKE'},
                        {field: 'account', title: __('Account'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        {field: 'remarks', title: __('Remarks'), operate: 'LIKE'},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}

                        {
                            field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'refuse',
                                    text: '拒绝',
                                    icon: 'fa fa-times',
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    url: 'usertx/record/refuse',
                                    confirm:'确认拒绝提现申请?',
                                    success: function () {
                                        $('.btn-refresh').trigger('click');
                                    },
                                    visible:function (row){
                                        if(row.status == '1'){
                                            return true;
                                        }
                                        return false;
                                    },
                                },
                                {
                                    name: 'manual',
                                    text: '手动提现',
                                    icon: 'fa fa-rmb',
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    url: 'usertx/record/manual',
                                    confirm:'确认手动提现完成?',
                                    success: function () {
                                        $('.btn-refresh').trigger('click');
                                    },
                                    visible:function (row){
                                        if(row.status == '1'){
                                            return true;
                                        }
                                        return false;
                                    },
                                },
                                {
                                    name: 'manual',
                                    text: '微信提现',
                                    icon: 'fa fa-weixin',
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    url: 'usertx/record/batches',
                                    confirm:'是否确认微信提现?',
                                    success: function () {
                                        $('.btn-refresh').trigger('click');
                                    },
                                    visible:function (row){
                                        if(row.status == '1'){
                                            return true;
                                        }
                                        return false;
                                    },
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
